package com.ruoyi.bus;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.entity.BusTaskGroupEntity;
import com.ruoyi.entity.mapper.BusTaskGroupMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 任务分组controller
 */
@RestController
@RequestMapping("/group")
public class TaskGroupController {

    @Autowired
    BusTaskGroupMapper taskGroupMapper;

    /**
     * 获取分组列表
     * @param level 必填
     * @param parentId  父id，如果没有就是0
     * @param userId 必填
     * @param rootId 不填就获取level 0的分组
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public R<List<BusTaskGroupEntity>> list(
            @RequestParam(value = "leven",required = false) Integer level,
            @RequestParam(value = "parentId",required = false) Integer parentId,
            @RequestParam(value = "userId",required = true) Integer userId,
            @RequestParam(value = "rootId",required = false) Integer rootId)
    {
        List<BusTaskGroupEntity> groups = taskGroupMapper.getGroups(userId, rootId, parentId, level);
        return R.ok(groups);
    }

    //添加分组
    @PostMapping("/add")
    @ResponseBody
    public R<Integer> add(@RequestBody BusTaskGroupEntity entity) {
        int result = taskGroupMapper.insertTask(entity);
        return R.ok(result);
    }

    //编辑分组
    @PostMapping("/edit")
    @ResponseBody
    public R<String> edit()
    {
        return R.ok("");
    }
}
